package com.cskaoyan.service.impl;

import com.cskaoyan.bean.bo.CollectListBo;
import com.cskaoyan.bean.pojo.MallCollect;
import com.cskaoyan.bean.vo.CollectListVo;
import com.cskaoyan.bean.vo.CollectVo;
import com.cskaoyan.bean.vo.TypeVo;
import com.cskaoyan.mapper.MallCollectMapper;
import com.cskaoyan.mapper.MallUserMapper;
import com.cskaoyan.service.CollectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author: ycb
 * @description: 收藏
 * @time: 2021/7/12 17:26
 */
@Service
public class CollectServiceImpl implements CollectService {

    @Autowired
    MallCollectMapper collectMapper;

    /**
     * @Author ycb
     * @description: 收藏列表
     * @Date 17:19 2021/7/12
     * url:http://182.92.235.201:8083/wx/collect/list?type=0&page=1&size=10
     */
    @Override
    public CollectListVo getColletList(Integer id, Integer type, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<CollectVo> collectList = collectMapper.queryColletById(id);

        PageInfo<CollectVo> collectVoPageInfo = new PageInfo<>(collectList);
        long total = collectVoPageInfo.getTotal();
        return new CollectListVo(collectList,total);
    }


    /**
     * @Author ycb
     * @description: 收藏商品增删
     * @Date 20:34 2021/7/12
     * url: http://182.92.235.201:8083/wx/collect/addordelete
     */
    @Override
    public TypeVo addOrDeleteColletion(Integer id, Integer type, Integer valueId) {
        Integer cid = collectMapper.queryColletByUidAndVid(id,valueId);

        if (cid != null){
            collectMapper.deleteByPrimaryKey(cid);
            return new TypeVo("delete");
        }else {
            collectMapper.insertCollet(cid,id,valueId,type,new Date(),new Date(),0);
            return new TypeVo("add");
        }

    }
}